# 输入性别页面
# 值：01检查号码 02年龄
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QAction, qApp, QDesktopWidget, QLabel, QPushButton, QMessageBox
from PyQt5.QtGui import QIcon, QFont
from bone import Bones

class Gender(QMainWindow):
    def __init__(self, text='', age=''):
        super().__init__()
        # 传递检查号码,年龄
        global jianchahao_text, age_text
        jianchahao_text = text
        age_text = age
        self.initUI()

    def initUI(self):
        exitAction = QAction(QIcon('images/exit.png'), 'Exit', self)
        exitAction.setShortcut('Ctrl+Q')
        exitAction.triggered.connect(qApp.quit)

        self.toolbar = self.addToolBar('Exit')
        self.toolbar.addAction(exitAction)

        lbl_jianchahao = QLabel('检查号：' + jianchahao_text, self)
        lbl_jianchahao.setFont(QFont('SansSerif', 16))
        lbl_jianchahao.resize(200, 50)
        lbl_jianchahao.move(100, 50)

        lbl_jianchahao = QLabel('年龄：' + age_text, self)
        lbl_jianchahao.setFont(QFont('SansSerif', 16))
        lbl_jianchahao.resize(200, 50)
        lbl_jianchahao.move(300, 50)

        # 创建性别 按钮

        btn = QPushButton('男', self)
        btn.setFont(QFont('SansSerif', 30))
        btn.resize(150, 150)
        btn.move(50, 150)
        btn.clicked.connect(self.checkGenderMale)

        btn = QPushButton('女', self)
        btn.setFont(QFont('SansSerif', 30))
        btn.resize(150, 150)
        btn.move(300, 150)
        btn.clicked.connect(self.checkGenderFeMale)

        # 操控按钮
        btn = QPushButton('返回', self)
        btn.setFont(QFont('SansSerif', 14))
        btn.resize(100, 60)
        btn.move(100, 400)
        btn.clicked.connect(self.on_back_clicked)

        # btn_next.clicked.connect(self.on_next_clicked)

        self.setFixedSize(500, 500)
        self.setWindowTitle('玉环县人民医院 TW3骨龄法 软件')
        self.setWindowIcon(QIcon("images/myicon.png"))
        self.center()
        self.show()

    # 点击返回按钮的时候 引入主界面并将自己销毁
    def on_back_clicked(self):
        from age import Age
        self.window().destroy()
        self.diag = Age(jianchahao_text, age_text)
        self.diag.show()

    def checkGenderMale(self):
        from sqlite import insert
        insert(jianchahao_text,1,'GENDER','num')

        self.window().hide()
        self.diag = Bones(jianchahao_text,'1',age_text)
        self.diag.show()

    def checkGenderFeMale(self):
        from sqlite import insert
        insert(jianchahao_text,0,'GENDER','num')

        self.diag = Bones(jianchahao_text,'0',age_text)
        self.diag.show()
        self.window().hide()

    def center(self):
        qr = self.frameGeometry()
        cp = QDesktopWidget().availableGeometry().center()
        qr.moveCenter(cp)
        self.move(qr.topLeft())

    def closeEvent(self, QCloseEvent):
        reply = QMessageBox.question(self, '退出？', "确定退出吗?",
                                     QMessageBox.Yes, QMessageBox.No)
        if reply == QMessageBox.Yes:
            QCloseEvent.accept()
            qApp.quit
        else:
            QCloseEvent.ignore()
